package com.bing.bing.contro;

import com.bing.bing.pojo.Student;
import com.bing.bing.pojo.User;
import com.bing.bing.servi.MyService;
import com.bing.bing.servi.MyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class MyContro {

    @Autowired(required = false)
    MyServiceImpl myserviceImpl;

    @Autowired(required = false)
    MyService myService;

//    @Autowired
//    private DistributedLockHandler distributedLockHandler;

/*    @Autowired
    GetListFeign feign;*/

    @GetMapping("biu")
    public List<Student> getList() {
        return myService.getList();
    }

    @GetMapping("{id}")
    public Student findById(@PathVariable Integer id) {
        Student stu = myserviceImpl.findById(id);
        System.out.println("111111111111111111");
        System.out.println("2");
        if (stu == null) {
            Student byId = myserviceImpl.findById(1);
            return byId;
        }
        return stu;
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public void save(@RequestParam(required = false, value = "name") String name) {
        myService.saveUser(name);

    }

//    @RequestMapping("/index")
//    public String index(){
//        Lock lock=new Lock("lynn","min");
//        if(distributedLockHandler.tryLock(lock)){
//            try {
//                //为了演示锁的效果，这里睡眠5000毫秒
//                System.out.println("执行方法");
//                Thread.sleep(5000);
//            }catch (Exception e){
//                e.printStackTrace();
//            }
//            distributedLockHandler.releaseLock(lock);
//        }
//        return "hello world!";
//    }

    @GetMapping("test")
    public User testAp() {
        User user = new User();
        user.setName("11");
        user.setAge(18);
        return user;
    }

}
